package com.x.gzcrm.web.controller;

import com.x.gzcrm.model.Permission;
import com.x.gzcrm.service.IPermissionService;
import com.x.gzcrm.utils.ValidateImageCodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    IPermissionService iPermissionService;


    Logger logger = LoggerFactory.getLogger(IndexController.class);

    @RequestMapping("/index")
    public String getindex(Model model)
    {

        System.out.println("helloworld!");
        logger.info("helloworld!");
        logger.error("helloworld!");
        logger.warn("helloworld!");
//        1>有写try-catch代码的时候，记得要在catch里写logger.error
//        2>如果没有自己捕获异常，logback也会把异常当做Error记录在日志文件
        try{
            int i = 10 / 0;
        }catch (Exception e){
            logger.error("除数不能为0");
        }





        //读取菜单
        List<Permission> menuList = iPermissionService.findAllMenus();
        model.addAttribute("menuList",menuList);
//        for (Permission menu : menuList)
//        {
//            System.out.println("主菜单"+menu);
//            for (Permission sub : menu.getSubMenus() )
//            {
//                System.out.println("子菜单"+sub);
//            }
//        }


        return "index";
    }
    @RequestMapping("/403")
    public String error403(){
        System.out.println("没有该权限");
        return "403";
    }


}
